// pages/homepage/search/searchdetail/searchdetail.js
var app = getApp();
Page({
  data: {
    id: '',
    name: '',
    carbohydrate: '',
    cellulose: '',
    sugarcontent: '',
  },
  onShareAppMessage: function () {
  },
  onLoad: function (e) {
    var that = this
    var formdata;
    console.info('--------' + e.name);
    this.setData({
      name: e.name,
    }),
    formdata = e.name;
    console.log('666'),
      wx.request({
        url: app.globalData.url + '/API/food?name=' + formdata,
        method: 'get',
        header: {
          'content-type': 'application/json'
          //'content-type': 'application/json;charset=utf-8'
          //'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
        },
        success: function (res) {
          console.log(res.data);
          var list = res.data;
          if (list == null) {
            var toastText = '数据获取失败';
            wx.showToast({
              title: toastText,
              icon: '',
              duration: 2000
            });
          } else {
            that.setData({
              list: list
            })
          }
        },
        fail: function () {
          console.log("------------fail-------------");
        }
      })
  },
  return: function () {
    wx.navigateTo({
      url: '../../homepage',
    })
  }
})